package com.siecom.transport.usbport.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbManager;

import com.siecom.tool.LogUtil;

public class UsbDetachedReceiver extends BroadcastReceiver {

    private static final String TAG = UsbDetachedReceiver.class.getSimpleName();
    private UsbDetachedListener mUsbDetachedListener;

    public UsbDetachedReceiver(UsbDetachedListener usbDetachedListener) {
        mUsbDetachedListener = usbDetachedListener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        LogUtil.e(TAG,"action == " + action);
        if (action.equals(UsbManager.ACTION_USB_ACCESSORY_DETACHED)){
            mUsbDetachedListener.usbDetached();
        }
        if (action.equals(UsbManager.ACTION_USB_ACCESSORY_ATTACHED)){
            mUsbDetachedListener.usbAttached();
        }
    }

    public interface UsbDetachedListener {
        /**
         * usb断开连接
         */
        void usbDetached();
        void usbAttached();
    }
}
